<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <!-- http://api.xiaohigh.com -->
    <button>王者荣耀</button>
    <button>英雄联盟</button>
    <hr>
    <!-- http://127.0.0.1:3000 -->
    <button>电影</button>
    <button>图书</button>

    <script>
        //当一个前端项目需要请求多个后台服务的接口时,必须使用cerate()
        //实际项目:都会用create
        //create方法返回是一个函数


        const newAxios1 = axios.create({
            baseURL:'http://api.xiaohigh.com',
            timeout:20000
        })

        const newAxios2 = axios.create({
            baseURL:'http://127.0.0.1:3000',
            timeout:30000
        })








        const btns = document.querySelectorAll('button')

        btns[0].onclick = async function(){
            newAxios1('/heros')
        }

        btns[1].onclick = async function(){
            newAxios1('/lol')
        }

        btns[2].onclick = async function(){
            newAxios2('/movie')
        }
        
        btns[3].onclick = async function(){
            newAxios2('/book')
        }









    </script>
</body>
</html>